//
//  bumenyewuViewController.m
//  PASystem
//
//  Created by michael on 16/7/21.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "bumenyewuViewController.h"
#import "huiyuanshiwusuoViewController.h"
#import "bangongsiViewController.h"
#import "falvTableViewController.h"
#import "dangweiTableViewController.h"
#import "zhanlanTableViewController.h"
#import "guojilianluoTableViewController.h"
@interface bumenyewuViewController ()

@end

@implementation bumenyewuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.title =@"部门管理";

        _array = [NSMutableArray array];

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];

 NSString *json =[NSString stringWithFormat: @"{'action':'getJurisdiction','service':'UserService', 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,name:部门管理}'}",userId,pwdId,userHumber];
     NSArray * array = @[@{@"arg0":json}];

     [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
     NSArray *array0 = JSON[@"reason"];
     NSDictionary *dic = [array0 firstObject];
    NSArray *array = dic[@"value"];
    for (NSDictionary *dic in array) {
    NSString *string = dic [@"name"];
    [_array addObject:string];
}
         [self _button];
         NSLog(@"%@",JSON);
         
         

    } failure:^(NSError *error) {
        
    }];






//    _array = @[@"办公室",@"会员事务部",@"国际联络部",@"展览部",@"法律部",@"机关党委"];
//创建按钮
     [self _button];

    // Do any additional setup after loading the view.
}
- (void)_button{
    float width = (kScreenWidth-90)/2.0;
    float height = (KScreenHeight-200-46)/4.0;
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc]init];
    flowlayout.itemSize = CGSizeMake(width, height);
       flowlayout.sectionInset = UIEdgeInsetsMake(40, 30, 40, 30);

    flowlayout.minimumInteritemSpacing = 20;
    flowlayout.minimumLineSpacing = 40;
 _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) collectionViewLayout:flowlayout];
  _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.backgroundView = nil;
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellid"];

    [self.view addSubview:_collectionView];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _array.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    static NSString * CellIdentifier = @"GradientCell";  

    UICollectionViewCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
    UIImageView *image = [[UIImageView alloc]initWithFrame:cell.contentView.frame];
    image.image = [UIImage imageNamed:_array[indexPath.row]];
    [cell.contentView addSubview:image];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

NSString *str = _array[indexPath.row];
NSLog(@"%@",str);
if ([str isEqualToString:@"办公室"]) {
bangongsiViewController *vc = [[bangongsiViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
//会员事务所
if ([str isEqualToString:@"会员事务部"]) {
huiyuanshiwusuoViewController *vc = [[huiyuanshiwusuoViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
//    self.navigationController
}
//法律部
if ([str isEqualToString:@"法律事务部"]) {
falvTableViewController *vc = [[falvTableViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
//党委机关
if ([str isEqualToString:@"机关党委"]) {
dangweiTableViewController *vc = [[dangweiTableViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
//guojilianluoTableViewController

if ([str isEqualToString:@"展览部"]) {
zhanlanTableViewController *vc = [[zhanlanTableViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
// 国际联络部
if ([str isEqualToString:@"国际联络部"]) {
guojilianluoTableViewController *vc = [[guojilianluoTableViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}

}
//展览部
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
